package lib

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func Json(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, data)
}

func WriteString(gc *gin.Context, code int, data interface{}) {
	rid, _ := gc.Get("RequireID")
	res := map[string]interface{}{
		"code":       code,
		"request_id": rid,
		"message":    GetCodeMsg(code),
	}
	if data != nil {
		res["data"] = data
	}
	gc.JSON(http.StatusOK, res)
}

func WriteString2(gc *gin.Context, code int, msg string, data interface{}) {
	rid, _ := gc.Get("RequireID")
	res := map[string]interface{}{
		"code":       code,
		"request_id": rid,
		"message":    msg,
	}
	if data != nil {
		res["data"] = data
	}
	gc.JSON(http.StatusOK, res)
}
